<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/10/24
 * Time: 16:40
 */

namespace app\api2\controller;

use app\common\model\Member;
use app\common\model\Sms;
use think\Cache;
use think\Controller;
use think\Request;
use app\common\controller\UtilController;
<<<<<<< HEAD

class MobileController extends ApiBaseController

=======
use app\common\controller\CaptchaController;

class MobileController extends ApiBaseController
>>>>>>> 6c451c11ed20a1abfa3f179a07ac647fb23a5b3e
{

    function index(){
        die('更改手机号');
    }

    function VerifyMobile(){
        $token = Request::instance()->get('access_token');
        if ($mobile = Request::instance()->get('mobile') && $password = Request::instance()->get('password')){
            $password  = md5($password);
            $res = Member::where('password','eq',$mobile)
                ->where('mobile','eq',$mobile)
                ->where('id','eq',$this->UserInfo['uid'])
                ->find();
            if ($res){
                $this->Msg = '验证成功';
                $this->Success = true;
                $this->UserInfo['MobileSuccess'] = true;
                Cache::set($this->Token,$this->UserInfo);
                return $this->call();
                $this->Data = $this->UserInfo;
          		return UtilController::jsonResponse(['Success'=>$this->Success,'Msg'=>$this->Msg,'Data'=>$this->Data]);


            }
        }
        $this->Msg = '验证失败';
        $this->Success = false;
        return UtilController::jsonResponse(['Success'=>$this->Success,'Msg'=>$this->Msg,'Data'=>$this->Data]);
    }

    function changeMobile(){
        if ($this->UserInfo['MobileSuccess'] == true){
            $mobile = Request::instance()->get('mobile');
            $verifyCode = Sms::getSms($mobile);
            if ($verifyCode == Request::instance()->get('verifyCode')){
                $this->Success = false;
                $res = Member::update(

                    ['mobile' => $mobile],
                    ['id' => $this->UserInfo['uid']]
                );
                $this->Msg = $res ? '修改成功' : '修改失败';
                $this->Success = $res;
            }else{
                $this->Msg = '验证码错误';
                $this->Success = false;
            }
        }else{
            $this->Msg = '请先验证手机';
            $this->Success = false;
        }
        return UtilController::jsonResponse(['Success'=>$this->Success,'Msg'=>$this->Msg,'Data'=>$this->Data]);
    }
    function test(){
        echo "123";
    }


}